package run.halo.app.repository;

import org.jetbrains.annotations.NotNull;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import run.halo.app.model.entity.TodoList;
import run.halo.app.repository.base.BaseRepository;

import javax.transaction.Transactional;
import java.util.List;

public interface TodoListRepository extends BaseRepository<TodoList, Integer> {

    @Query("select todo from TodoList todo where todo.todoState = :status")
    List<TodoList> findAllByToDoStatus(@Param("status") Integer status);

    @Query("select todo from TodoList todo where todo.todoType = :type")
    List<TodoList> findAllByTodoType(@Param("type") Integer type);

    @Transactional
    @Modifying
    @Query("update TodoList todo set todo.todoState = :status where todo.id = :id")
    int updateStatus(@Param("id") Integer id, @Param("status") Integer status);

}
